package com.york.aclservice.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * Copyright(C),2021,伯海晟科技有限公司
 * FileName:MyMetaObjectHandler
 * Author:yangboxiong
 * Date:2021/5/2 11:18
 * Description:自动填充日期
 * History:
 * <author>       <time>      <version>       <desc>
 * 作者姓名       修改时间        版本号         描述
 *
 * @author yangboxiong
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 创建日期
     *
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        //实现填充业务逻辑
        this.strictInsertFill(metaObject, "gmtCreate", LocalDateTime.class, LocalDateTime.now());
        this.strictUpdateFill(metaObject, "gmtModified", LocalDateTime.class, LocalDateTime.now());
    }


    /**
     * 更新日期
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "gmtModified", LocalDateTime.class, LocalDateTime.now());
    }
}
